# 银行管理系统

# 定义一个用于存放账号信息的列表
stulist = [
    {'account':'dd123','password':'aadt1232','money':1010},
    {'account':'tt123','password':'onth1965','money':30220},
    {'account':'yy123','password':'ntsx1201','money':920}
]

stulist_m =[
    {'account':'admin','password':'admin'}
]

#定义一个银行的输出函数
def showStu(stulist):
    '''
    银行信息的输出函数
    '''
    if len(stulist)== 0:
        print("======== 没有银行信息可以输出！ ========")
        return
    print("|{0:<5}| {1:<10}| {2:<10}|".format("sid","account","password"))
    print("-"*40)
    for i in range(len(stulist)):
        print("|{0:<5}| {1:<10}| {2:<10}|".format(i+1,stulist[i]['account'],stulist[i]['password']),stulist[i]['money'])
def showStu_g(stulist,i):
    '''
    银行个人信息的输出函数
    '''
    print("| {0:<10}| {1:<10}| {2:<10}|".format("account","password","money"))
    print("-"*40)
    print("| {0:<10}| {1:<10}| {2:<10}|".format(stulist[i]['account'],stulist[i]['password'],stulist[i]['money']))

if __name__ == "__main__":
    pos = 0
    while True:
        # 输出初始界面
        print("="*12,'银行管理系统',"="*14)
        print("=" * 12, "账户登录类型选择", "=" * 14)
        print("{0:1} {1:13} {2:15}".format(" ", "1.普通用户登录", "2.管理员登录"))
        print("{0:1} {1:13}".format(" ", "3.退出系统"))
        print("="*40)
        key_type = input("请输入对应的选择：")
        if key_type == "1":
            while True:
                account_ghost = input("请输入账户：")
                password_ghost = input("请输入密码：")
                pos = 0
                flag = False
                for x in stulist:
                    if x['account'] == account_ghost and x['password'] == password_ghost:
                        flag = True
                        break
                    pos += 1
                if flag == False:
                    print("======= 账户或密码错误 ========")
                else:
                    break
            while True:
                print("=" * 12, '用户系统', "=" * 14)
                print("{0:1} {1:13} {2:15}".format(" ", "1.账号信息查询", "2.存款"))
                print("{0:1} {1:13} {2:15}".format(" ", "3.取款", "4.返回上一层"))
                print("=" * 40)
                key_ghost = input("请输入对应的选择：")
                if key_ghost == "1":
                    print("=" * 12, "账户信息浏览", "=" * 14)
                    showStu_g(stulist,pos)
                    input("按回车键继续：")
                elif key_ghost == "2":
                    print("=" * 12, "存款", "=" * 14)
                    count_money = key_ghost = input("请输入需要存款的金额：")
                    count_money = int(count_money)
                    stulist[pos]['money'] += count_money
                    input("按回车键继续：")
                elif key_ghost == "3":
                    print("=" * 12, "取款", "=" * 14)
                    count_money = key_ghost = input("请输入需要取款的金额：")
                    count_money = int(count_money)
                    stulist[pos]['money'] -= count_money
                    input("按回车键继续：")
                elif key_ghost == "4":
                    break
                else:
                    print("======= 无效指令 ========")

        elif key_type == "2":
            while True:
                account_ghost = input("请输入账户：")
                password_ghost = input("请输入密码：")
                pos = 1
                flag = False
                for x in stulist_m:
                    if x['account'] == account_ghost and x['password'] == password_ghost:
                        flag = True
                        break
                    pos += 1
                if flag == False:
                    print("======= 账户或密码错误 ========")
                else:
                    break
            while True:
                print("=" * 12, '管理管理员系统', "=" * 14)
                print("{0:1} {1:13} {2:15}".format(" ", "1.账号信息查询", "2.添加账户信息"))
                print("{0:1} {1:13} {2:15}".format(" ", "3.删除账户信息", "4.返回上一层"))
                print("=" * 40)
                key = input("请输入对应的选择：")
                # 根据键盘值，判断并执行对应的操作
                if key == "1":
                    print("=" * 12, "账户信息浏览", "=" * 14)
                    showStu(stulist)
                    input("按回车键继续：")
                elif key == "2":
                    print("="*12,"账户信息添加","="*14)
                    stu={}
                    stu['account'] = input("请输入要添加的账户：")
                    stu['password'] = input("请输入要添加的密码：")
                    stu['money'] = input("请输入要添加的账户余额：")
                    stulist.append(stu)
                    showStu(stulist)
                    input("按回车键继续：")
                elif key == "3":
                    print("="*12,"账户信息删除","="*14)
                    showStu(stulist)
                    sid = input("请输入你要删除的信息id号：")
                    del stulist[int(sid)-1]
                    showStu(stulist)
                    input("按回车键继续：")
                elif key == "4":
                    break
                else:
                    print("======= 无效指令 ========")
        elif key_type == "3":
            print("=" * 12, "再见", "=" * 14)
            break
        else:
            print("======= 无效指令 ========")